package com.lyb.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.service.SysUserService;
import com.lyb.spzx.model.dto.system.SysUserDto;
import com.lyb.spzx.model.dto.system.system.SysUser;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserCoctroller {

    @Autowired
    private SysUserService sysUserService;

    @Operation(summary = "用户分页查询")
    @GetMapping("/findUserByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findUserByPage(@PathVariable(name = "pageNum") Integer pageNum,
                                                    @PathVariable(name = "pageSize") Integer pageSize,
                                                    SysUserDto sysUserDto){
        System.out.println("pageNum = " + pageNum + ", pageSize = " + pageSize + ", sysUserDto = " + sysUserDto);
        PageInfo<SysUser> userPageInfo = sysUserService.findUserByPage(pageNum, pageSize, sysUserDto);
        return Result.build(userPageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加用户")
    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改用户")
    @PutMapping("/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("deleteUserById/{id}")
    public Result deleteUserById(@PathVariable(name = "id") Integer id){
        sysUserService.deleteUserById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
